package com.sun.dailyprj.zotye.ui;

import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.sun.common.recyclerview.BaseBindingAdapter;
import com.sun.dailyprj.R;
import com.sun.dailyprj.databinding.ActivityDetailBinding;
import com.sun.dailyprj.zotye.viewmodel.UpgradeAdapter;

/*
 * =====================================================================================
 * Summary:
 *
 * File: DetailActivity.java
 * Author: Yanpeng.Sun
 * Create: 2019/9/25 16:40
 * =====================================================================================
 */
public class DetailActivity extends AppCompatActivity implements UpgradeAdapter.OnItemClickListener{
    ActivityDetailBinding mBinding;
    private LinearLayoutManager layoutManager;
    private int pg;

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_detail);
        mBinding.setDetail(this);
        layoutManager = new LinearLayoutManager(this);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mBinding.rvDetail.setLayoutManager(layoutManager);
        UpgradeAdapter adapter = new UpgradeAdapter(this);
        mBinding.rvDetail.setAdapter(adapter);
        adapter.setOnItemClickListener(this);

    }

   /* public void startDownload(View view) {
        Log.i("syp","onClick()");
        mBinding.btnDlDetail.setVisibility(View.GONE);
        mBinding.rlPgDetail.setVisibility(View.VISIBLE);

        new Thread(new Runnable(){
            @Override
            public void run() {
                for(int i = 0; i < 101; i++){
                    try{
                        Thread.sleep(1000);
                        pg = i;
                        runOnUiThread(new Runnable(){
                            @Override
                            public void run() {
                                mBinding.pgDetail.setProgress(pg);
                                mBinding.tvPgDetail.setText(pg+"%");
                            }
                        });
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }).start();
    }
*/
    @Override
    public void onItemClick(View v, BaseBindingAdapter.ViewName viewName, int position) {
        Log.e("syp","onItemClick() note has click , position:" + position);
    }

    @Override
    public void onItemLongClick(View v) {

    }
}
